package com.xxwy.lifecycle.singleton;

import com.xxwy.lifecycle.bean.User;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 单例，这里展示外部代理，内部单例在代码.
 *
 * @author xxwy
 * @date 2021/7/13 0013
 */
public class SingletonTest {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(SingletonTest.class);
        // 内部：debug: AbstractApplicationContext.prepareBeanFactory： registerSingleton
        applicationContext.refresh();

        DefaultListableBeanFactory listableBeanFactory = applicationContext.getDefaultListableBeanFactory();
        // 外部singleton
        listableBeanFactory.registerSingleton("xxx", new User("xxx", 3));

        // resolveDependency
        applicationContext.close();
    }

}
